<!-- 提现管理 -->
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="display: flex;justify-content: space-between;">
			<div>
				<p class="text">提现管理</p>
			</div>
			<el-form :inline="true">
				<el-form-item >
					<el-button type="primary" @click="Inquire(0)" icon="el-icon-search">查询免审列表</el-button>
				</el-form-item>
				<el-form-item >
					<el-button type="primary" @click="Inquire(1)" icon="el-icon-search">查询待审列表</el-button>
				</el-form-item>
				<el-form-item >
					<el-button type="success" @click="Inquire(2)" icon="el-icon-search">查询通过列表</el-button>
				</el-form-item>
				<el-form-item >
					<el-button type="danger" @click="Inquire(3)" icon="el-icon-search">查询拒绝列表</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="Inquire(4)" icon="el-icon-search">自定义查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="UserList" highlight-current-row v-loading="loading" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column type="expand">
			  <template slot-scope="props">
			    <el-form label-position="left" inline class="demo-table-expand">
					<el-form-item label="微信订单号:">
						<span>{{ props.row.paymentNo }}</span>
					</el-form-item>
					<el-form-item label="商户转账订单号:">
						<span>{{ props.row.partnerTradeNo }}</span>
					</el-form-item>
					<el-form-item label="微信支付时间:">
						<span>{{ props.row.paymentTime }}</span>
					</el-form-item>
					<el-form-item label="用户 ID:">
						<span>{{ props.row.userId }}</span>
					</el-form-item>
			    </el-form>
			  </template>
			</el-table-column>
			<el-table-column prop="id" align="center" label="ID" width="80"></el-table-column>
			<el-table-column prop="realName" align="center" label="姓名"></el-table-column>
			<el-table-column prop="phone" align="center" label="手机号"></el-table-column>
			<el-table-column prop="userMoney" align="center" label="账户余额"></el-table-column>
			<el-table-column prop="money" align="center" label="提现金额" width="120"></el-table-column>
			<el-table-column prop="moneyFee" align="center" label="手续费"></el-table-column>
			<el-table-column prop="txCount" align="center" label="提现次数"></el-table-column>
			<el-table-column prop="checkStatus" align="center" label="审核状态" width="160">
				<template slot-scope="scope">
					<p v-if="scope.row.checkStatus == '0'">免审</p>
					<p v-if="scope.row.checkStatus == '1'">待审</p>
					<p v-if="scope.row.checkStatus == '2'">通过</p>
					<p v-if="scope.row.checkStatus == '3'">拒绝</p>
				</template>
			</el-table-column>
			<el-table-column prop="payMode" align="center" label="支付方式">
				<template slot-scope="scope">
					<p v-if="scope.row.payMode == '1'">微信</p>
					<p v-if="scope.row.payMode == '2'">支付宝</p>
				</template>
			</el-table-column>
			<el-table-column prop="ctime" align="center" label="发起时间" width="160" >
			</el-table-column>
			<el-table-column label="操作" width="200">
				<template slot-scope="scope">
					<el-button v-if="scope.row.checkStatus == '1'" type="success" size="small" @click="By(scope.$index, scope.row)" icon="el-icon-s-check">通过</el-button>
					<el-button v-else-if="scope.row.checkStatus == '2' && !scope.row.commissionMoney" size="small" type="success" icon="el-icon-success" @click="btn(1)">已通过</el-button>
					<el-button v-if="scope.row.checkStatus == '1'" size="small" type="danger" @click="Refuse(scope.$index, scope.row)" icon="el-icon-delete">拒绝</el-button>
					<el-button v-else-if="scope.row.checkStatus == '3'" size="small" type="danger" icon="el-icon-error" @click="btn(2)">已拒绝</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!-- 自定义查询 cusexcel-->
		<el-dialog title="自定义查询" :visible.sync="cusdialog" width="35%" :before-close="handleClose">
			<el-form :model="cusForm" label-width="105px" ref="cusForm">
				<el-form-item label="手机号" prop="phone">
					<el-input v-model="cusForm.phone" auto-complete="off" placeholder="请输入正确的手机号" style="width: 220px;"></el-input>
				</el-form-item>
				<!-- <el-form-item label="账号" prop="account">
					<el-input v-model="cusForm.account" auto-complete="off" placeholder="请输入正确的账号" style="width: 220px;"></el-input>
				</el-form-item> -->
				<el-form-item label="查询状态选择" prop="wgsStatus">
					<el-radio-group v-model="cusForm.wgsStatus">
						<el-radio class="radio" :label="0">免审</el-radio>
						<el-radio class="radio" :label="1">待审</el-radio>
						<el-radio class="radio" :label="2">通过</el-radio>
						<el-radio class="radio" :label="3">拒绝</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="cusdialog = false">取 消</el-button>
				<el-button type="primary"  @click.native="cusSubmit" >确定</el-button>
			</span>
		</el-dialog>
		<!-- 自定义导出 -->
		<el-dialog title="自定义导出" :visible.sync="cusexcel" width="35%" :before-close="handleClose">
			<el-form :model="excelForm" label-width="105px" ref="excelForm">
				<el-form-item label="手机号" prop="phone">
					<el-input v-model="excelForm.phone" auto-complete="off" placeholder="请输入正确的手机号" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="账号" prop="account">
					<el-input v-model="excelForm.account" auto-complete="off" placeholder="请输入正确的账号" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="查询状态选择" prop="wgsStatus">
					<el-radio-group v-model="excelForm.wgsStatus">
						<el-radio class="radio" :label="-1">全部</el-radio>
						<el-radio class="radio" :label="0">待审核</el-radio>
						<el-radio class="radio" :label="1">审核通过</el-radio>
						<el-radio class="radio" :label="2">拒绝</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="cusexcel = false">取 消</el-button>
				<el-button type="primary"  @click.native="excelSubmit" >确定</el-button>
			</span>
		</el-dialog>
	</section>
</template>
<script>
	import {
		getwallList,
		editwallList,
		Refreshtoken
	} from '../../../api/api';
	
	export default {
		data() {
			return {
				loading: false,
				UserList: [],
				sels: [],//列表选中列81560
				total: 0,
				page: 1,
				size:10,
				status:'',
				timer: null,
				// 自定义查询
				cusdialog:false,
				cusForm:{
					phone:'',
					wgsStatus:'-2'
				},
				//自定义下载
				cusexcel:false,
				excelForm:{
					phone:'',
					wgsStatus:'-2'
				}
			}
		},
		mounted() {
			this.getList()
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
		},
		methods: {
			//获取列表
			getList:function(type){
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp,checkStatus:this.status,};
				this.loading = true;
				getwallList(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.UserList = res.data.list;
						this.loading = false;
					}
				});
			},
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			Inquire(type){
				if (type == '1') {
					this.status = 1
					this.getList()
				} else if(type == '2'){
					this.status = 2
					this.getList()
				}else if(type == '0'){
					this.status = 0
					this.getList()
				}else if(type =='3'){
					this.status = 3
					this.getList()
				}else if(type == '4'){
					this.cusdialog = true
				}
			},
			btn(a){
				if(a=='1'){
					this.$notify({
					  title: '审核成功',
					  message: '该用户已通过审核',
					  type: 'success'
					});
				}else if(a=='2'){
					this.$notify.error({
					  title: '审核失败',
					  message: '该用户未通过审核',
					  type: 'success'
					});
				}
			},
			// 通过审核
			By:function(index, row){
				this.$confirm('是否通过该用户的申请?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
					var Token = sessionStorage.getItem('Token');
					var timestamp = new Date().getTime();
					var para = {token: Token,timestamp: timestamp,id:row.id,checkStatus:2};
					editwallList(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$message({
								type: 'success',
								message: '通过申请!'
							});
							this.loading = false;
							this.getList();
						}
					});
				}).catch(() => {
				  this.$message({
					type: 'info',
					message: '已取消'
				  });
				});
			},
			// 拒绝审核
			Refuse:function(index,row){
				this.$confirm('是否拒绝该用户的申请?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
				  var Token = sessionStorage.getItem('Token');
				  var timestamp = new Date().getTime();
				  var para = {token: Token,timestamp: timestamp,id:row.id,checkStatus:3};
				  editwallList(para).then((res) => {
				  	var res = res.data;
				  	if (res.code != 0) {
				  		this.$message({
				  			message: res.message,
				  			type: 'error'
				  		});
				  	} else {
				  		this.$message({
				  			type: 'success',
				  			message: '拒绝申请!'
				  		});
				  		this.loading = false;
				  		this.getList();
				  	}
				  });
				}).catch(() => {
				  this.$message({
					type: 'info',
					message: '已取消'
				  });
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			cellStyle({row, column}){
				return 'text-align:center;padding:2px;';
			},
			rowClass({row, column}){
				return 'text-align:center';
			},
			handleSizeChange(val) {
				this.size = val;
				this.getList();
			},
			handleCurrentChange(currentPage) {
				this.page = currentPage;
				this.getList();
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
				.catch(_ => {});
			},
			//条件查询
			cusSubmit(){
				if (this.cusForm.wgsStatus == '-2') {
					this.$notify({ title: '警告', message: '查询状态状态为必选项', type: 'warning' });
				}else{
					this.cusdialog = true;
					var Token = sessionStorage.getItem('Token');
					var timestamp = new Date().getTime();
					if (this.cusForm.phone != '') {
						var para = {token: Token,timestamp: timestamp,curpage:this.page,pagesize:this.size,checkStatus:this.cusForm.wgsStatus,phone:this.cusForm.phone};
					}
					getwallList(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$message({
								message: '查询成功',
								type: 'success'
							});
							this.$refs['cusForm'].resetFields();
							this.cusdialog = false;
							this.total = res.data.total;
							this.UserList = res.data.list;
							this.loading = false;
						}
					});
				}
			},
			// 自定义导出
			excelSubmit(){
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				if (this.excelForm.wgsStatus == '-2') {
					this.$notify({title: '警告',message: '下载状态为必选项',type: 'warning'});
				} else{
					if (this.excelForm.phone != '') {
						var para = {token: Token,wgsType:1,wgsStatus:this.excelForm.wgsStatus,timestamp: timestamp,phone:this.excelForm.phone,};
					}else if(this.excelForm.account != ''){
						var para = {token: Token,wgsType:1,wgsStatus:this.excelForm.wgsStatus,timestamp: timestamp,account:this.excelForm.account};
					}
					this.loading = true;
					uploadWgsList(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$refs['excelForm'].resetFields();
							this.cusexcel = false;
							window.location.href = res.data
							this.loading = false;
						}
					});
				}
			}
		},
		
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.el-select .el-input .el-input--suffix .el-input__inner {
    width: 130px !important;
  }  
  
  .demo-table-expand {
  	display: flex;
  	flex-direction: column;
      font-size: 0;
    }
    .demo-table-expand label {
      width: 90px;
      color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
      margin-right: 0;
      margin-bottom: 0;
      width: 50%;
    }
</style>

